<template>
    <div class="loginForm">
   <div class="main">
   <div class="wrapper">
    <!-- 导航 -->
  
  <van-tabs v-model="activeName">
  <van-tab title="账号登录" name="a">
  <el-form>
  <!--  -->
    <el-form-item >
    <el-input
      v-model=" Form.account"
      placeholder="Please input"
      class="input-with-select"
    >
      <template #prepend>
        <el-button :icon="User" />
      </template>
    
    </el-input>
    </el-form-item>
    <!--  -->
     <el-form-item>
     <el-input
     
      v-model="Form.password"
      placeholder="Please input"
      class="input-with-select"
      type='password'
    >
      <template #prepend>
        <el-button :icon="Lock" />
      </template>
    
     </el-input>
     </el-form-item>
      <el-form-item>
      <el-checkbox v-model="checked1" label="我已阅读" size="large"  @change='changeSel'/>
      <a href="">《隐私条款》</a>和
      <a href="">《服务条款》</a>
       <p class="error" v-show="checked1===false">请勾选登录协议</p>
      </el-form-item>
       <el-form-item>
      <el-button @click="login">登录</el-button>
      </el-form-item>
      <!-- <el-icon><Lock /></el-icon> -->
  </el-form>
  </van-tab>
  <van-tab title="扫码登录" name="b">扫码登录</van-tab>

</van-tabs>
</div>
</div>
    </div>
</template>

<script setup>
import { ref ,reactive} from 'vue'
import { Search,User,Lock } from '@element-plus/icons-vue'
import {Login} from '@/api/http'
import { ElMessage } from 'element-plus'
import { useStore } from 'vuex'
import { useRoute, useRouter } from 'vue-router'
const router = useRouter()
const store = useStore()
const route = useRoute()
const activeName = ref('a')
const checked1 = ref(true)
const handleClick = (tab ,event) => {
  console.log(tab, event)
}
const changeSel = (val) =>{
console.log(val)
checked1.value = val

}
const Form =  reactive({
    account:"xiaotuxian001",
    password:"123456",
})
const login = async() =>{
    console.log('login')
     const { account, password } = Form
     const { data: res} = await Login({ account, password })
     console.log(res)
     if(res.code ==='1'){
       
  const { id, account, avatar, mobile, nickname, token } = res.result
          store.commit('user/setUser', { id, account, avatar, mobile, nickname, token })
          store.dispatch('cart/mergeCart').then(() => {
            // console.log(res)
            // 进行跳转
             router.push(route.query.redirectUrl || '/')
              ElMessage({
              message: '登录成功',
              type: 'success',
          })
          })
          }else{
              ElMessage({
    message: '登录失败',
    type: 'error',
  })
          }
}

</script>

<style lang="less" scoped>
.main{
    width: 1240px;
    margin: 0 auto;
    position: relative;
}
.loginForm{
    width: 100%;
    height: 488px;
    background: url('@/assets/image/login-bg.696efec3.png') no-repeat 50%/cover;
}
.wrapper{
    width: 380px;
    background: #fff;
    min-height: 400px;
    position: absolute;
    left: 50%;
    top: 54px;
    transform: translate3d(100px,0,0);
    box-shadow: 0 0 10px rgb(0 0 0 / 15%);
}

 .van-tab__panel{
    min-height: 300px;
    padding: 20px;
 }
 .el-form{
    padding: 10px;
    
.el-input:nth-child(2){
    margin-top: 30px;
}
 }

 .el-checkbox__input.is-checked .el-checkbox__inner {
    background-color: #7eb822;
    border-color: var(--el-checkbox-checked-input-border-color);
 
}
.error{
    color: red;
    font-size: 10px;
    padding: 0;
}
.el-button{
    width: 100%;
    background-color: #27BA9B;
    color: #333;
}
</style>